package array.pgm1;

/*
 * Create a class Matrix. Internal representation of this class will be a two
 * dimensional array of size 10 by 10. In addition, the class should have
 * following data members and member functions:
 *  -> Data members:
 *  -> Int rows
 *  -> Int columns
 *  -> Member functions
 *  -> Constructors
 *  a.	The default constructor
 *      Matrix()
 *      This should set each of the array element to zero.
 *  b.	Overloaded constructor
 *      Matrix(int, int)
 *      This constructor should call the default constructor first. It should
 *      then assign the value of first parameter to rows, and the value of the
 *      second parameter to columns. You can assume that the values of both the
 *      parameters will be less than or equal to 10.
 *  c.	Void SetElement(int r, int c, int value)
 *      This function should set the array element at row r and column c to the
 *      value val. This assignment should be done only if
 *      o	val is positive
 *      o	r and c are valid
 *      else the element should be set to zero.
 *  d.	Matrix Transpose ()
 *  	This function should transpose the matrix. Transpose of a matrix is
 *  	another matrix where the elements in rows of the first matrix become
 *  	elements of the corresponding columns in the new matrix. Provide a
 *  	function to print a Matrix object.
 */

public class Matrix {
	private int rows;
	private int column;
	private int[][] array;

	public Matrix() {
		this.rows = 10;
		this.column = 10;
		array = new int[this.rows][this.column];
	}

	public Matrix(int r, int c) {
		this();
		if (r < 10 && c < 10 && c >= 0 && r >= 0) {
			this.rows = r;
			this.column = c;
		}
	}

	void SetElement(int r, int c, int value) {
		if (r >= 0 && c >= 0 && r <= this.rows && c <= this.column)
			if (value > 0)
				this.array[r][c] = value;
			else
				this.array[r][c] = 0;
	}

	int GetElement(int r, int c) {
		if (r >= 0 && c >= 0 && r <= this.rows && c <= this.column)
			return this.array[r][c];
		else
			return 0;

	}

	Matrix Transpose() {
		Matrix tmp = new Matrix(this.column, this.rows);
		for (int i = 0; i < this.column; i++)
			for (int j = 0; j < this.rows; j++)
				tmp.SetElement(i, j, this.GetElement(j, i));
		return tmp;
	}

	void display() {
		for (int i = 0; i < this.rows; i++) {
			for (int j = 0; j < this.column; j++)
				System.out.print(this.array[i][j] + "   ");
			System.out.println();
		}
	}

	public int getRows() {
		return rows;
	}

	public int getColumn() {
		return column;
	}
}
